<HTML> <HEAD> <TITLE>Problem E: Graphical Editor</TITLE> </HEAD>
<BODY LANG="EN" BGCOLOR=#FFFFFF>
 <H1><BR CLEAR=ALL><CENTER><TABLE BGCOLOR=#0060F0><TR><TD><B><FONT SIZE=5 COLOR=#C0FFFF>&nbsp;Problem E: Graphical Editor</FONT>&nbsp;</B></TABLE></CENTER></H1>
<P>

<H2><FONT COLOR=#0070E8><A NAME="Graphical
Editor">Problem</A></FONT></H2> <P>

The simple graphical editor deals with a rectangular table
<I>M&times;N (1&LT;=M,N&LT;=250)</I>. Each pixel of the table has its colour.
The picture is formed from this square pixels.
<P>
The problem is to write a program, which simulates an interactive
work of the graphical editor.

</U></U><H2><FONT COLOR=#0070E8>Input</FONT></H2> <P> Input
consists of the editor commands, one per line. Each command is
represented by one Latin capital placed in the very beginning of the line. If the command
supposes
parameters, all the parameters will be given in the same line
separated by space. As the parameters there may be: the
coordinates of the pixel - two integers, the first one is the column
number and belongs to <I>1..M,</I> the second one is the row
number and belongs to <I>1..N,</I> the origin is
in the upper left corner of the table; the colour - the Latin
capital; file name - in MSDOS 8.3 format.<P>

The editor deals with the following commands:<P>

<center><table border=1 cellspacing=1.5 cellpadding=5>
<tr>
  <td> I&nbsp;M&nbsp;N </td>
  <td> Creates a new table <i>M&times;N.</i> All the pixels are colored in white&nbsp;<i>(O).</i>
</tr>
<tr>
  <td> C </td>
  <td> Clears the table. The size remains the same.  All the pixels became white&nbsp;<i>(O).</i>
</tr>
<tr>
  <td> L&nbsp;X&nbsp;Y&nbsp;C </td>
  <td> Colors the pixel with coordinates <i>(X,Y)</i> in colour&nbsp;<i>C.</i>
</tr>
<tr>
  <td> V&nbsp;X&nbsp;Y1&nbsp;Y2&nbsp;C </td>
  <td> Draws the vertical segment in the column <I>X</I> between the rows <I>Y1</I> and <I>Y2</I> inclusive in colour&nbsp;<i>C.</i>
</tr>
<tr>
  <td> H&nbsp;X1&nbsp;X2&nbsp;Y&nbsp;C </td>
  <td> Draws the horizontal segment in the row <I>Y </I> between the columns <I>X1</I> and <I>X2</I> inclusive in colour&nbsp;<i>C.</i>
</tr>
<tr>
  <td> K&nbsp;X1&nbsp;Y1&nbsp;X2&nbsp;Y2&nbsp;C </td>
  <td> Draws the filled rectangle in colour <I>C</I>. <I>(X1,Y1)</I> is the upper left corner, <I>(X2,Y2)</I> is the lower right corner of the rectangle.
</tr>
<tr>
  <td> F&nbsp;X&nbsp;Y&nbsp;C </td>
  <td> Fills the region with the colour <I>C</I>. The region <I>R</I> to be
  filled is defined as follows. The pixel&nbsp;<I>(X,Y)</I>
  belongs to this region. The other pixel belongs to
  the region&nbsp;<I>R</I> if and only if it has the same colour
  as pixel&nbsp;<I>(X,Y)</I> and
  a common side with any
  pixel which belongs to this region.
  </td>
</tr>
<tr>
  <td> S Name </td>
  <td> Writes the picture in the file <i>Name.</i>
</tr>
<tr>
  <td> X </td>
  <td> Terminates the session.</i>
</tr>
</table></center>


<H2><FONT COLOR=#0070E8>Output</FONT></H2> <P>
Every time the command <I>S NAME</I> meets, you should output the
file name <I>NAME</I> and the current table, row by row. Each row
is represented by a pixels' colours series, see the output sample.

<H2><FONT COLOR=#0070E8>Errors</FONT></H2> <P>

If as a command there will be a character different from
<I>I, C, L, V, H, K, F, S, X,</I> the editor should ignore the whole line and pass to the next
command.<P>

In case of other errors the program behaviour is unpredictable.

<H2><FONT COLOR=#0070E8>Sample Input</FONT></H2> <P> <PRE>
I 5 6
L 2 3 A
S one.bmp
G 2 3 J
F 3 3 J
V 2 3 4 W
H 3 4 2 Z
S two.bmp
X
</PRE> <P>

<H2><FONT COLOR=#0070E8>Sample Output</A></FONT></H2> <P> <PRE>
one.bmp
OOOOO
OOOOO
OAOOO
OOOOO
OOOOO
OOOOO
two.bmp
JJJJJ
JJZZJ
JWJJJ
JWJJJ
JJJJJ
JJJJJ
<span style='mso-bidi-font-size:13.5pt;color:windowtext'>
<hr size=2 width="100%" align=center>
<span style='mso-bidi-font-size:13.5pt;color:windowtext'> </span>
<H4>Alexander Denisjuk, 2002</H4> </PRE> </BODY> </HTML>
